using System;
using System.Collections.Generic;
using GGEditor.API;
using GGEditor.API.Documents;
using GGEditor.API.Plugins;

namespace GGEditor.Core.Documents
{
	public interface IFileExporterDefinition
	{
		string Name { get; }
		string Text { get; }
		string FileExtension { get; }
		Type ModelType { get; }
		IFileExporter Exporter { get; }
	}

	public class FileExporterDefinition : IFileExporterDefinition
	{
		#region Implementation of IFileExporterDefinition

		public string Name { get; set; }
		public string Text { get; set; }
		public string FileExtension { get; set; }
		public Type ModelType { get; set; }
		public IFileExporter Exporter { get; set; }

		#endregion

		#region XmlNodeObjectFactory

		[XmlNodeObjectFactory(Name = "FileExporter")]
		public class FileExporterDefinitionFactory : IXmlNodeObjectFactory
		{
			#region Implementation of IXmlNodeObjectFactory

			public object Build(IPluginNode pluginNode, IDictionary<string, string> attributes)
			{
				return new FileExporterDefinition()
				{
					FileExtension = attributes["ext"],
					Name = attributes["name"],
					Text = attributes["text"],
					ModelType = ObjectCreator.FindType(
						pluginNode.Plugin.Assemblies, attributes["model"]),
					Exporter = ObjectCreator.Create<IFileExporter>(
						pluginNode.Plugin.Assemblies, attributes["type"])
				};
			}

			#endregion
		}

		#endregion
	}
}